﻿//-----------------------------------------------------------------
//
// @(#)$Id: RoymailAndPayPalSendCountryDetails.aspx.cs,v 1.0 2013/12/13 17:47:07 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:47:07 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_BasTableAdapters;
using ebay.Dal.CenterDB_EbayTableAdapters;

public partial class UI_Bas_RoymailAndPayPalSendCountryDetails : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
//        T_CountryTableAdapter adapter = new T_CountryTableAdapter();
        T_EbayCountryTableAdapter adapter = new T_EbayCountryTableAdapter();
        ddlPayPalSendCountryName.DataSource = adapter.GetData();
        ddlPayPalSendCountryName.DataTextField = "CountryName";
        ddlPayPalSendCountryName.DataBind();
        ddlRoymailSendCountryName.DataSource = adapter.GetData();
        ddlRoymailSendCountryName.DataTextField = "CountryName";
        ddlRoymailSendCountryName.DataBind(); 
    }
    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {           
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        break;
                    case "U":
                        this.txtSendId.Attributes["readonly"] = "readonly";
                        int sendId = int.Parse(Request.QueryString["id"]);
                        T_RoymailAndPayPalSendCountryTableAdapter ebayAdapter = new T_RoymailAndPayPalSendCountryTableAdapter();
                        DataTable dt = ebayAdapter.GetDataBySendId(sendId );                        
                        DataRow r = dt.Rows[0];                       
                        txtSendId.Value = r["SendId"].ToString();
                        ddlRoymailSendCountryName.Text = r["RoymailSendCountryName"].ToString();
                        ddlPayPalSendCountryName.Text = r["PayPalSendCountryName"].ToString();                        
                        break;
                }
            }

        }
    }
  
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_RoymailAndPayPalSendCountryTableAdapter ebayAdapter = new T_RoymailAndPayPalSendCountryTableAdapter();
                         int flag = (int)ebayAdapter.IsExists(int.Parse(txtSendId.Value));
                         if (flag == 0)
                         {
                             int val = ebayAdapter.Insert(
                                      int.Parse(txtSendId.Value),
                                      ddlRoymailSendCountryName.SelectedValue,
                                      ddlPayPalSendCountryName.SelectedValue
                                      );
                             if (val > 0)
                             {
                                 Response.Write("<script>alert('添加成功!');window.location.href='RoymailAndPayPalSendCountry.aspx'</script>");
                             }
                         }
                         else
                         {
                             Response.Write("<script>alert('编号重复!...');</script>");
                         }
                    }
                    break;
                case "U":
                    {
                        T_RoymailAndPayPalSendCountryTableAdapter ebayAdapter = new T_RoymailAndPayPalSendCountryTableAdapter();
                        int val = ebayAdapter.Update(
                              ddlRoymailSendCountryName .SelectedValue ,
                              ddlPayPalSendCountryName .SelectedValue ,
                              Convert.ToInt32(txtSendId.Value)
                               );
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='RoymailAndPayPalSendCountry.aspx'</script>");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
